<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <%@include file="../includes/common.jsp" %>
    <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <%@ page contentType="text/html;charset=UTF-8" %>

    <title>课件上传列表</title>
</head>
<body>
<div class="container-fluid" style="padding: 0">
    <div class="row-fluid">

        <div style="padding: 10px">
            <form class="form-inline">
                课件名称：<input type="text" class="input-medium" name="scormName" id="scormName"
                            value=""/>
                课件类别：
                <input type="text" id="showCourseType" name="showCourseType" flag="course_type" autocomplete="off">
                <input type="hidden" id="courseType" name="courseType" autoHidden="autoHidden">
                <span>
                上传日期：<input type="text"  data-date-format="yyyy-mm-dd" id="upDateBegin" name="upDateBegin" readonly="readonly" onclick="getDateBegin()">
                </span>
                <span>
                    至<input type="text"  data-date-format="yyyy-mm-dd" id="upDateEnd" readonly="readonly" name="upDateEnd" onclick="getDateEnd()">
                </span>
                <a class="btn btn-primary" onclick="query()">查找</a>
                <a class="btn btn-primary" onclick="deleteUser()">删除</a>
            </form>
            <table id="dataTable"></table>
            <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
                <iframe style="width: 100%;height: 100%"
                        id="contentFrame"
                        name="contentFrame"
                        marginheight="0"
                        marginwidth="0"
                        frameborder="0" src=""
                        allowTransparency="true">
                </iframe>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    function query() {
        listOption.url = basePath+"scormZip/listAllUp";
        listOption.data = "scormName="+$("#scormName").val().trim()+"&showCourseType="+$("#courseType").val()
        +"&upDateBegin="+$("#upDateBegin").val()+"&upDateEnd="+$("#upDateEnd").val();
        listOption.pageNumber = 1;
        loadData(listOption);
    }
    var today = new Date().dateFormat();
    var dateConf = {
        language: 'zh-CN',
        endDate: today,
        weekStart: 1,
        todayBtn: true,
        autoClose: true,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    };
    var dateConfs = {
        language: 'zh-CN',
        startDate:$("#upDateBegin").val() ,
        endDate: today,
        weekStart: 1,
        todayBtn: true,
        autoClose: true,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    };
    function getDateBegin(){
        $("#upDateBegin").datetimepicker(dateConf);
        autoComplete();
        JC.inputInit();
    }
    function getDateEnd(){
        $("#upDateEnd").datetimepicker(dateConfs);
        autoComplete();
        JC.inputInit();
    }


    function deleteUser() {
        var ids = "";
        var value;
        var flag = 0;
        var allBox = $("[name='deleteUserCheckBox']");
        for (var i = 0; i < allBox.length; i++) {
            value = allBox[i].getAttribute("value");
            if ($("#" + value).attr("checked") == "checked") {
                flag = 1;
                ids += value + ",";
            }
        }
        if (flag == 0) {
            $.messager.alert("提示", "请选择删除用户");
            return;
        }
        $.messager.confirm("提示", "确认删除？", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "scormZip/delCourse?ids=" + ids,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("成功", "删除成功！", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
    }

    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='deleteUserCheckBox']").attr("checked", true);
        } else {
            $("[name='deleteUserCheckBox']").attr("checked", false);
        }
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "课件列表",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'id', title: "&nbsp;<input id='checkAll' type='checkbox' onclick='selectAll()'/>", align: 'center', width: 100},
                    {field: 'scormName', title: '课件名称', sortable: true, align: 'center', width: 300},
                    {field: 'showCourseType', title: '课件类别', sortable: true, align: 'center', width: 100},
                    {field: 'uploadTime', title: '上传时间', align: 'center', width: 300},
                    {field: 'courseDisc', title: '课程描述', align: 'center', width: 200},
                    {field: 'showUserName', title: '上传者', align: 'center', width: 200} ,
                    {field: 'edit', title: '操作', align: 'center', width: 200}
                ]
            ],
            sortName: "",
            sortOrder: "",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "scormName":
                sortColumn = "scorm_name";
                break;
            case "courseType":
                sortColumn = "course_type";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function queryFormat(temp) {
        var rowDataList = [];
        for (var i in temp) {
            idBtn = "&nbsp;<input type='checkbox' name='deleteUserCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            editBtn = "&nbsp;<a onclick='studyCourse(\"" + temp[i].id + "\")'>学习</a>&nbsp;";
            temp[i].id = idBtn;
            temp[i].edit = editBtn;
            rowDataList.push(temp[i]);
        }
        return rowDataList;
    }

    function studyCourse(id){

         window.location.href=basePath+"scormZip/playScorm?id="+id;
    }

    $(function () {
        initDataGrid();
        query();
    });
</script>